package cn.com.open.itembank.controller;

import cn.com.open.itembank.dto.CopyCourseModel;
import cn.com.open.itembank.dto.ReturnModel;
import cn.com.open.itembank.entity.CourseItemBank;
import cn.com.open.itembank.service.ChapterService;
import cn.com.open.itembank.service.ItemBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * Created by lucky on 2017/9/5.
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    ItemBankService service;

    @Autowired
    ChapterService chapterService;

    /**
     * 根据资源课程id获取可用题库信息.
     *
     * @param courseId 资源课程id
     * @return 可用题库信息
     */
    @GetMapping(value = "/{id}")
    public CourseItemBank getCourseItemBankInfoByCourseId(@PathVariable(value = "id") String courseId) {
        return service.getCourseItemBankInfoByCourseId(courseId);
    }

    /**
     * 复制课程题库.
     *
     * @param sourceCourseId 源资源课程ID（被共享的课程）
     * @param courseModel    复制课程模型
     * @return the return model
     */
    @PostMapping(value = "/{id}/copy")
    public ReturnModel copy(@PathVariable(value = "id") String sourceCourseId, @RequestBody CopyCourseModel courseModel) {
        return service.copy(sourceCourseId, courseModel);
    }

    /**
     * 判断给定的appkey是否拥有给定的资源课程id的管理权限
     *
     * @param courseID 资源id
     * @param appKey     appkey
     * @return true ，拥有；false，不拥有
     */
    @GetMapping(value = "/{id}/coursepermission")
    public boolean coursePermission(@PathVariable(value = "id") String courseID, @RequestParam("appId") String appKey) {
        return service.coursePermission(courseID, appKey);
    }

    /**
     * Redis 查询题数集合,返回课程和题数
     * @return
     */
    @GetMapping("/findcoursequestioncount")
    public ReturnModel findCourseQuestionCount(){
        return service.findCourseQuestionCount();
    }

    /**
     * 根据课程Id获取章节（外部课程）
     * @param appKey
     * @param courseId
     * @return
     */
    @GetMapping(value = "/{courseId}/getchapter")
    public ReturnModel getChapterByCourseId(@RequestParam("appKey") String appKey,
                                            @PathVariable("courseId") String courseId) {
        return chapterService.getChapterByCourseId(appKey,courseId);
    }
}
